package com.glsc.ngateway.opmanage.service;

import java.time.LocalDateTime;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;

import com.glsc.ngateway.common.base.domain.mysql.opmanagemain.skill.SkillFileInfo;
import com.glsc.ngateway.common.base.repo.mysql.opmanagemain.skill.SkillRepository;
import com.glsc.ngateway.opmanage.utils.DateUtils;

import static com.glsc.ngateway.opmanage.utils.DateUtils.formatDate_;

/**
 * @author houzhc
 * @description: TODO hzc
 * @date 2024年11月06日
 */
@Service
public class SkillService {

    @Autowired
    private SkillRepository skillRepository;

    public void save(SkillFileInfo sKillFileInfo) {
        sKillFileInfo.setCreateTime(LocalDateTime.now());
        sKillFileInfo.setCreateDate(DateUtils.getCurrentDate(formatDate_));
        skillRepository.save(sKillFileInfo);
    }

    public void deleteById(Integer id) {
        skillRepository.deleteById(id);
    }

    public Page<SkillFileInfo> page(Specification spec, Integer pageNo, Integer pageSize) {
        Sort.Direction direction = Sort.Direction.DESC;
        String sort = "id";
        Pageable pageable = PageRequest.of(pageNo - 1, pageSize, direction, sort);
        return skillRepository.findAll(spec, pageable);
    }
}
